package com.ms.p2p.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.ms.p2p.bean.PageBean;
import com.ms.p2p.controller.BaseController;
import com.ms.p2p.entity.member.Auth;
import com.ms.p2p.entity.member.Email;
import com.ms.p2p.entity.member.Member;
import com.ms.p2p.provider.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import sun.misc.BASE64Decoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping({ "/member/ucenter" })
public class MemberUcenterController extends BaseController {

	@Reference
	private CertiFiCationProvider certificationProvider;
	@Reference
	private MailAuthProvider mailAuthProvider;
	@Reference
	private AdminUserProvider adminUserProvider;
	@Reference
	private MemberProvider memberProvider;
	@Reference
	private SettingProvider settingProvider;

	@Reference
	MemberAccountBankProvider memberAccountBankProvider;


	@RequestMapping({ "/safe" })
	public String passwdAndQuestion(HttpSession session,
			HttpServletRequest request) {
		Member user = getCurrentUser();
		Email email = mailAuthProvider.findByUserId(user.getId());
		Auth realName = certificationProvider.findByUserId(user.getId());
		request.setAttribute("email", email);
		request.setAttribute("realName", realName);

		return "/customer/member/ucenter/safe/index";
	}

	@RequestMapping({ "/deal" })
	public String passwdAndDeal(HttpSession session,
									HttpServletRequest request) {
		Member user = getCurrentUser();
		Auth realName = certificationProvider.findByUserId(user.getId());
		request.setAttribute("realName", realName);
		return "/customer/member/ucenter/safe/index_deal";
	}


	/**
	 * 用BASE64加密
	 *
	 * @param str
	 * @return
	 */
	public static String getBASE64(String str) {
		byte[] b = str.getBytes();
		String s = null;
		if (b != null) {
			s = new sun.misc.BASE64Encoder().encode(b);
		}
		return s;
	}
	/**
	 * 解密BASE64字窜
	 *
	 * @param s
	 * @return
	 */
	public static String getFromBASE64(String s) {
		byte[] b = null;
		if (s != null) {
			BASE64Decoder decoder = new BASE64Decoder();
			try {
				b = decoder.decodeBuffer(s);
				return new String(b);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return new String(b);
	}
}
